"""
组织架构页面（含员工信息查看和部门岗位查看功能）
封装组织架构页面元素定位器和操作方法
"""
from selenium.webdriver.common.by import By
from page.base_page import BasePage
from time import sleep


class OrganizationPage(BasePage):
    # 组织架构页面路径
    url = "/index.php?m=organization"

    # 元素定位器
    # 1. 用户名菜单相关
    username_menu_btn_locator = (By.XPATH, "/html/body/div[1]/div/div/div[2]/ul[2]/li[6]/a")  # 右上角用户名菜单（魏佳旭）

    # 2. 组织架构按钮（下拉菜单中）
    organization_btn_locator = (By.LINK_TEXT, "组织架构")  # 下拉菜单中的“组织架构”链接

    # 3. 查看按钮（员工信息入口）
    view_btn_locator = (By.CSS_SELECTOR, "#user_form > div:nth-child(1) > ul > li > ul > li > a")  # 查看按钮

    # 4. 员工链接（进入员工信息页面）
    employees_link_locator = (By.LINK_TEXT, "员工")  # “员工”链接

    # 5. 组织架构页面相关
    organization_page_locator = (By.CSS_SELECTOR, "body > div.container > div.page-header > h4 > small > a:nth-child(1)")
    department_post_locator = (By.CSS_SELECTOR, "body > div.container > div.row > form > div:nth-child(1) > div > a:nth-child(2)")

    # 操作方法
    def click_username_menu_btn(self):
        """点击右上角用户名菜单（展开下拉菜单）"""
        print("点击右上角用户名菜单（魏佳旭）...")
        self.click(self.username_menu_btn_locator)
        sleep(2)

    def click_organization_btn(self):
        """点击下拉菜单中的“组织架构”链接"""
        self.click(self.organization_btn_locator)
        sleep(2)

    def switch_to_organization_page(self):
        """封装完整切换流程：点击用户名菜单→点击组织架构"""
        self.click_username_menu_btn()
        self.click_organization_btn()

    def click_organization_page_button(self):
        """点击组织架构页面按钮"""
        self.click(self.organization_page_locator)
        sleep(2)

    def click_department_post(self):
        """点击查看部门岗位图"""
        self.click(self.department_post_locator)
        sleep(2)

    def view_department_post(self):
        """封装完整查看部门岗位流程"""
        self.switch_to_organization_page()
        self.click_organization_page_button()
        self.click_department_post()

    def click_view_btn(self):
        """点击“查看”按钮（打开员工信息入口）"""
        self.click(self.view_btn_locator)
        sleep(2)

    def click_employees_link(self):
        """点击“员工”链接（进入员工信息页面）"""
        self.click(self.employees_link_locator)
        sleep(2)

    def view_employee_info(self):
        """封装完整查看员工信息流程：点击查看→点击员工"""
        self.click_view_btn()
        self.click_employees_link()
